package gofish.objects;

import java.util.ArrayList;

/**
 * Game holds information pertaining to one active game of
 * Go Fish. It holds such information as the gid, the turn,
 * and the players (Player objects) involved.
 * Either Kylyn or myself will make the final version of this
 * class. This particular version of the class is more of a
 * draft just to test the simulator.
 *
 * @author Matt Lauber
 */
public class Game {

	private int gid;
	private int turn;
	private ArrayList<Player> players = new ArrayList<Player>();
	//private int eid; // remove
	
	public Game(int gid) {
		
		this.gid = gid;
		//this.deck = deck;
		//this.players = players;
		
		this.turn = 0;
		//this.eid = 0;
		
	}
	
	public int getGid() {
		return gid;
	}
	
	public void addPlayer(Player player) {
		players.add(player);
	}
	
//	public int getEid() {
//		return eid;
//	}
	
	public int getTurn() {
		return turn;
	}
	
	public ArrayList<Player> getPlayerMap() {
		return players;
	}
	
	public Player getPlayer(String userName) {
		
		for (int i = 0; i < players.size(); ++i) {
			Player p = players.get(i);
			if (p.getUserName().equals(userName)) {
				return p;
			}
		}
		
		return null;
	}
	
	public void incrementTurn() {
		++turn;
		turn %= players.size();
	}
	
	//shuffle
	//insertCards (to shuffle in if a player leaves)
	
	/*
	public int goFish(String userName, String soughtCard) {
		Player p = getPlayer(userName);
		String card = deck.substring(0, 2);
		deck = deck.substring(2);
		int response = -1;
		
		if (card.charAt(0) == soughtCard.charAt(0)) {
			response = GameData.FISHED_CORRECT_CARD;
			p.setPairs(p.getPairs() + card.charAt(0));
		}
		else if (p.getHand().contains(String.valueOf(card.charAt(0)))) {
			
		}
		// IF GAME OVER SET WIN FLAG WITH DB REQUEST, but which Servlet does this?
		p.setHand(p.getHand() + card);
		return response;
	}
	*/
}
